//
//  ViewController.m
//  SmartCoin
//
//  Created by apple on 2018/3/7.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "ViewController.h"
#import "LoginSellerViewController.h"
#import "LoginBuyyerViewController.h"
#import <ShareSDKExtension/ShareSDK+Extension.h>
//#import <IQKeyboardManager.h>
@interface ViewController ()

@end

@implementation ViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBarHidden = YES;
    //    [IQKeyboardManager sharedManager].enable = NO;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    self.view.backgroundColor = bggrayColor;
    [self viewLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)viewLoad{
    UIImageView *bgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, cx_hit)];
    bgview.image = [UIImage imageNamed:@"bg"];
    [self.view addSubview:bgview];
    
    UILabel *deslabel = [[UILabel alloc] initWithFrame:CGRectMake(0, cx_hit - 230 - cxsingler.bottomdis,cx_wid, 16)];
    deslabel.text = @"请选择您的登录身份";
    deslabel.font = [UIFont systemFontOfSize:12];
    deslabel.textAlignment = NSTextAlignmentCenter;
    deslabel.textColor = [UIColor lightTextColor];
    [self.view addSubview:deslabel];
    
#pragma mark--logo part
    for (NSInteger index = 0; index < 2; index ++) {
        UIView *layerview = [[UIView alloc] initWithFrame:CGRectMake(43 + cx_wid / 2 * index, cx_hit * (341.0 / 667) , cx_wid / 2 - 43 * 2, 1)];
        layerview.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:layerview];
    }
    
    UIImageView *logo = [[UIImageView alloc] init];
    logo.bounds = CGRectMake(0, 0, 44, 44);
    logo.layer.cornerRadius = 5;
    logo.image = [UIImage imageNamed:@"logo1"];
    logo.center = CGPointMake(cx_wid / 2, cx_hit * (341.0 / 667) + 0.5);
    [self.view addSubview:logo];
    
    
#pragma mark--入口按钮
    NSArray *enternames = @[@"商户入口",@"员工入口"];
    int num = 2;//展示按钮个数
    if ([ShareSDK isClientInstalled:SSDKPlatformTypeWechat]) {//当前手机安装有微信
        num = 2;
    }
    else{
        num = 1;
    }
    for (NSInteger index = 0; index < num; index ++) {
        UIButton *enterBtn = [[UIButton alloc] initWithFrame:CGRectMake(67, cx_hit - cxsingler.bottomdis - 95 - 56  - 40 + 56 * index, cx_wid - 134, 40)];
        CAGradientLayer *layer = [CAGradientLayer layer];
        layer.frame = CGRectMake(0, 0, cx_wid - 46 - 38 * 2, 40);
        layer.colors = @[(id)[CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1].CGColor,(id)[CXSinglerModel colorWithHex:@"#FE4438" alpha:1].CGColor];
        layer.startPoint = CGPointMake(0, 0);
        layer.endPoint = CGPointMake(1, 0);
        [enterBtn.layer addSublayer:layer];
        enterBtn.layer.cornerRadius = 20;
        enterBtn.clipsToBounds = YES;
        enterBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [enterBtn setTitle:enternames[index] forState:UIControlStateNormal];
        [enterBtn addTarget:self action:@selector(taped:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:enterBtn];
    }
}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing: YES];
}

-(void)taped:(UIButton *)sender{
    [self.view endEditing:YES];
    NSString *title = sender.titleLabel.text;
    if ([title isEqual:@"商户入口"]) {
        LoginSellerViewController *nextVC = [[LoginSellerViewController alloc] init];//进入商户登录
        [self.navigationController pushViewController:nextVC animated:YES];
    }
    else if([title isEqual:@"员工入口"]){
        LoginBuyyerViewController *nextVC = [[LoginBuyyerViewController alloc] init];//进入用户登录
        [self.navigationController pushViewController:nextVC animated:YES];
    }
}


-(void)loadXPart{//特殊定义iphonex顶部间隔部分，此处重写baseviewcontroller loadxpart方法
    if (cxsingler.topdis > 20) {
        UIView *topbg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, cxsingler.topdis)];

        UIView *bottombg = [[UIView alloc] initWithFrame:CGRectMake(0, cx_hit - cxsingler.bottomdis, cx_wid, cxsingler.bottomdis)];
        //        bottombg.backgroundColor = bggrayColor;
        for (NSInteger index = 0; index < 2; index ++) {
            CAGradientLayer *layer = [CAGradientLayer layer];
            
            layer.colors = @[(id)[CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1].CGColor,(id)[CXSinglerModel colorWithHex:@"#FE4438" alpha:1].CGColor];
            layer.startPoint = CGPointMake(0, 0);
            layer.endPoint = CGPointMake(1, 0);
            //            [enterBtn.layer addSublayer:layer];
            if (index == 0) {
                layer.frame = topbg.bounds;
                [topbg.layer addSublayer:layer];
            }
            else{
                layer.frame = bottombg.bounds;
                [bottombg.layer addSublayer:layer];
            }
        }
        UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur];
        effe.frame = topbg.frame;
        effe.layer.masksToBounds = YES;
        //        effe.layer.cornerRadius = 5;
        effe.alpha = 0.4;
        
        UIBlurEffect * secblur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView * seceffe = [[UIVisualEffectView alloc]initWithEffect:secblur];
        seceffe.frame = topbg.frame;
        seceffe.layer.masksToBounds = YES;
        seceffe.layer.cornerRadius = 5;
        seceffe.alpha = 0.4;
        
        [topbg addSubview:effe];
        [self.view addSubview:topbg];
        [bottombg addSubview:seceffe];
        [self.view addSubview:bottombg];
        [self.view sendSubviewToBack:topbg];
        [self.view sendSubviewToBack:bottombg];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
